package com.shop.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.common.core.domain.Result;
import com.shop.coupon.domain.Coupon;
import com.shop.coupon.domain.SkuLadder;
import com.shop.coupon.mapper.SkuLadderMapper;
import com.shop.coupon.service.SkuLadderService;
import org.springframework.stereotype.Service;

@Service
public class SkuLadderServiceImpl extends ServiceImpl<SkuLadderMapper , SkuLadder> implements SkuLadderService {
    private final SkuLadderMapper skuLadderMapper;
    public SkuLadderServiceImpl(SkuLadderMapper skuLadderMapper) {
        this.skuLadderMapper = skuLadderMapper;
    }


    /**
     * skuId商品专属折扣优惠券
     * @param pageNum
     * @return
     */
    @Override
    public Result skuIdLadder(Integer pageNum , Integer pageSize) {
        QueryWrapper<SkuLadder> queryWrapper = new QueryWrapper<>();
        Page<SkuLadder> ladderPage = new Page<>(pageNum, pageSize);
        Page<SkuLadder> selectPage = skuLadderMapper.selectPage(ladderPage,queryWrapper);
        return Result.success(selectPage);
    }


    /**
     * sku专属商品折扣优惠券规则修改
     * @param skuLadder
     * @return
     */
    @Override
    public Result skuLadderUpdateRule(SkuLadder skuLadder) {
        int skuLadderUpdateRule = baseMapper.updateById(skuLadder);
        return Result.success("修改成功"+skuLadderUpdateRule);
    }

    /**
     * sku专属商品折扣优惠券添加
     * @param skuLadder
     * @return
     */
    @Override
    public Result skuLadderInsert(SkuLadder skuLadder) {
        int skuLadderInsert = baseMapper.insert(skuLadder);
        return Result.success("sku专属商品折扣优惠券添加成功"+skuLadderInsert);
    }

    @Override
    public Result<SkuLadder> getSkuLadder(Long id) {
        SkuLadder skuLadder = baseMapper.selectById(id);
        return Result.success(skuLadder);
    }

    @Override
    public Result skuLadderDelete(Long id) {
        int deleteById = baseMapper.deleteById(id);
        return Result.success(deleteById);
    }
}
